import Vue from 'vue'
import VueRouter from 'vue-router'
import login from "../views/login";
import home from "../views/home";
import gongdan from "../components/gongdan/gongdan";
import advice from "../components/advice/advice";
import engineer from "../components/engineer/engineer";
import user from "../components/user/user";
import equipment from "../components/equipment/equipment";
import equipmentType from "../components/equipmentType/equipmentType";
import repairs from "../components/repairs/repairs";
import tutorial from "../components/tutorial/tutorial";
import tutorial_add_1 from "../components/tutorial/tutorial_add_1";

Vue.use(VueRouter);

  const routes = [
  {
    path: '/',
    redirect:'/login'
  },
    {
      path: '/login',
      component:login
    },
    {
      path:'/home',
      component:home,
      redirect:'/gongdan',
      children:[
        {path:'/gongdan',component:gongdan},
        {path: '/advice',component: advice},
        {path:'/engineer',component:engineer},
        {path:'/user',component:user},
        {path:'/equipment',component:equipment},
        {path:'/equipmentType',component:equipmentType},
        {path:'/repairs',component:repairs},
        {path:'/tutorial',component:tutorial},
        {path:'/tutroial_add',component:tutorial_add_1}

      ]
    }

];

const router = new VueRouter({
  routes
});
router.beforeEach((to,from,next)=>{
  if(to.path==='/login')
    return next();
  const tokenStr=window.sessionStorage.getItem('token');
  if(!tokenStr)
    return next('/login');
  next();
});

export default router
